// pages/selectMember/selectMember.js
const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    selected:-1
  },

  myFamilyMemberList(){
    Controller.myFamilyMemberList().then(res=>{
      if(res.code==0){
        let list = this.data.list
        list = list.concat(res.data.baseData)
        this.setData({
          list
        })
      }
    })
  },

  //跳转
  goPage(){
    if(this.data.selected==-1){
      wx.showToast({
        title: '请先选择成员',
        icon: 'none',
        duration: 1200
      });
      return
    }
    let id = this.data.list[this.data.selected].id
    let sex = this.data.list[this.data.selected].sex
    wx.navigateTo({ url:'/pages/testingList/testingList?id='+id+'&sex='+sex });
  },

  goAdd(){
    wx.navigateTo({ url:'/pages/addMember/addMember'});
  },

  select(e){
    let index = e.currentTarget.dataset["index"]
    index = Number(index)
    console.log(index)
    if(this.data.selected==index){
      this.setData({
        selected:-1
      })
      return
    }
    this.setData({
      selected:index
    })
  },

  getinfo(){
    Controller.getinfo().then(res=>{
      if(res.code==0){
        let data = res.data.baseData
        let list = []
        list.push({
          name:data.nick,
          id:'',
          relationship:'本人',
          sex:data.sex
        })
        console.log(list)
        this.setData({
          list
        })
        this.myFamilyMemberList()
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(options.parentid){
      app.globalData.parentid=options.parentid
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getinfo()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  onShareAppMessage: function (e) {
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
  onShareTimeline: function(res){
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
})